﻿﻿using NServiceBus;
using Framework.Infrastructure;
using Framework.Config;

namespace Framework.Bus
{
    public class MessageEndpoint : IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization
    {
        /// <summary>
        /// Perform initialization logic.
        /// </summary>
        public void Init()
        {
            var config = Config.Configuration.Instance
                               .NServieBusBuild();
            if (Config.Configuration.GetAppConfig<bool>("IsAsyncEventHandler"))
            {
                config.AsyncEventDispatcherBuild();
            }
            if (Config.Configuration.GetAppConfig<bool>("IsAsyncCommandHandler"))
            {
                config.CommandDispatcherBuild()
                       .DefaultEventBusBuild() ;
            }
        }
    }
}
